package com.zyzy.leftfourdead.adapter.dairyfoodadapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zyzy.leftfourdead.R;
import com.zyzy.leftfourdead.bean.DairyBean;
import com.zyzy.leftfourdead.helper.BaseAdapterHelper;

import java.util.List;

/**
 * Created by loverforever on 2016/8/21.
 * 最里面的listview的item的填充器
 */
public class DairyItemFragmentAdapter extends BaseAdapterHelper<DairyBean.ProductsBean> {
    private static final String TAG = "WateritemAdapter";

    public DairyItemFragmentAdapter(Context context, List<DairyBean.ProductsBean> list) {
        super(context, list);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent, List<DairyBean.ProductsBean> list, LayoutInflater inflater) {
        Log.i(TAG, "::::::::::getItemView: "+list.toString());
        ViewHolder viewHolder=null;
        //
        if(convertView==null){
            convertView=inflater.inflate(R.layout.item_small_fragment_water_listview,parent,false);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            //获取标签
            viewHolder= (ViewHolder) convertView.getTag();
        }

        final String imageUrl = list.get(position).getImage();
        if (imageUrl!=null){
            Glide.with(context).load(imageUrl).into(viewHolder.imageView_item_small_water_listView);
        }

        //给主标题赋值
        viewHolder.textView_item_small_water_name.setText(list.get(position).getName());
        //给副标题赋值
        viewHolder.textView_item_small_water_subtitle.setText(list.get(position).getSubtitle());
        //给会员价赋值
        viewHolder.textView_item_small_water_price.setText("会员价 "+(float)((list.get(position).getPrice())/100)+"");
        //viewHolder.textView_item_small_vip_price.setText();
        //给促销价赋值
        viewHolder.textView_item_small_vip_price_num.setText((float)((list.get(position).getVip_price())/100)+"");
        //对加入购物车按钮设置点击监听  点击之后样式改变 具体样式还没有设置
        viewHolder.button_item_small_shoppingCar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


        //返回convertView
        return convertView;
    }

    class ViewHolder{
        //左侧小图片
        private ImageView imageView_item_small_water_listView;
        //主标题
        private TextView textView_item_small_water_name;
        //副标题
        private TextView textView_item_small_water_subtitle;
        //会员价
        private TextView textView_item_small_water_price;
        //促销价 左边
        private TextView textView_item_small_vip_price;
        //促销价 实际的值
        private TextView textView_item_small_vip_price_num;
        //加入购物车
        private Button button_item_small_shoppingCar;

        public ViewHolder(View convertView){
            //初始化控件
            imageView_item_small_water_listView= (ImageView) convertView.findViewById(R.id.imageView_item_small_water_listView);
            textView_item_small_water_name= (TextView) convertView.findViewById(R.id.textView_item_small_water_name);
            textView_item_small_water_subtitle= (TextView) convertView.findViewById(R.id.textView_item_small_water_subtitle);
            textView_item_small_water_price= (TextView) convertView.findViewById(R.id.textView_item_small_water_price);
            textView_item_small_vip_price= (TextView) convertView.findViewById(R.id.textView_item_small_vip_price);
            textView_item_small_vip_price_num= (TextView) convertView.findViewById(R.id.textView_item_small_vip_price_num);
            button_item_small_shoppingCar= (Button) convertView.findViewById(R.id.button_item_small_shoppingCar);
        }
    }
}
